Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature zms 3434 print info on ekiosk ticket #727

Merged
merged 3 commits into from
Dec 19, 2024

Conversation

manjencic
Copy link
Contributor

@manjencic manjencic commented Dec 9, 2024

Description

Short description or comments

Reference

Issues #XXX

Summary by CodeRabbit

  • New Features

    • Added a hidden field for printText in multiple button blocks to enhance form data submission.
    • Conditional rendering of printText in the print template to display additional information after the contact name.
  • Bug Fixes

    • Improved handling of language configurations and default values for translations.
  • Documentation

    • Updated method functionality for readResponse to include a new variable for enhanced response rendering.

Copy link
Contributor

coderabbitai bot commented Dec 9, 2024

Walkthrough

The pull request introduces modifications across several files in the zmsticketprinter module, primarily focusing on enhancing the handling of translations and the incorporation of a new parameter for print functionality. In the Index class, the $translations array is initialized with a default key, and logic is added to manage the 'printText' key based on the current language. The Process class's readResponse method is updated to include a new $printText variable. Additionally, new hidden fields are added in the Twig templates to capture and display this print text.

Changes

File Path Change Summary
zmsticketprinter/src/Zmsticketprinter/Index.php Modified readResponse method to initialize $translations with 'printText' => '' and updated language handling logic.
zmsticketprinter/src/Zmsticketprinter/Process.php Updated readResponse method to include a new $printText variable retrieved from the request validator.
zmsticketprinter/templates/block/content/buttons.twig Added a hidden field printText in button_single, button_multi, and button_multi_deep blocks.
zmsticketprinter/templates/block/content/print.twig Modified print block to conditionally display printText after the contact name in the output.

Possibly related PRs

  • Feature zms 3418 ekiosk zwei standorte keine ou #718: The changes in the pageheader.twig file are related to the overall structure of the templates used in the project, which may indirectly connect to the handling of translations and display logic in the main PR.

Suggested reviewers

  • ThomasAFink

Poem

In the land where tickets gleam,
A printText field fulfills a dream.
With translations set just right,
Our forms now capture text in sight.
So hop along, let’s print away,
With every click, a brighter day! 🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef11b73 and 72161b3.

📒 Files selected for processing (1)
  • zmsticketprinter/templates/block/content/print.twig (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • zmsticketprinter/templates/block/content/print.twig

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🧹 Outside diff range and nitpick comments (3)
zmsticketprinter/templates/block/content/print.twig (1)

7-11: Consider improving text concatenation logic

The current implementation has two potential issues:

  1. Hardcoded period might cause double punctuation if printText already ends with punctuation
  2. Period concatenation might not be appropriate for all languages

Consider moving the period to the translation string itself for better localization support.

zmsticketprinter/src/Zmsticketprinter/Process.php (1)

59-59: Consider sanitizing printText before passing to template

While template escaping should be implemented, it's good practice to also sanitize data at the controller level.

Consider adding sanitization:

-                'printText' => $printText,
+                'printText' => strip_tags($printText),
zmsticketprinter/src/Zmsticketprinter/Index.php (1)

46-48: Consider using constant for translation keys

To avoid typos and maintain consistency, consider defining translation keys as class constants.

+    private const TRANSLATION_PRINT_TEXT = 'printText';
+
     $translations = [
-        'printText' => ''
+        self::TRANSLATION_PRINT_TEXT => ''
     ];
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8d4c63d and ef11b73.

📒 Files selected for processing (4)
  • zmsticketprinter/src/Zmsticketprinter/Index.php (2 hunks)
  • zmsticketprinter/src/Zmsticketprinter/Process.php (2 hunks)
  • zmsticketprinter/templates/block/content/buttons.twig (3 hunks)
  • zmsticketprinter/templates/block/content/print.twig (1 hunks)
🔇 Additional comments (1)
zmsticketprinter/templates/block/content/buttons.twig (1)

Line range hint 17-74: Verify translation system integration

The new printText functionality relies heavily on the translation system. Let's verify its implementation and available translations.

✅ Verification successful

Let me gather more information about the translation system integration, particularly focusing on the language configuration and defaultPrintText setting.


Based on the gathered information, I can now provide a final response about the translation system integration:

Translation system is properly integrated with printText functionality

The implementation shows a well-structured translation system where:

  • printText is correctly passed through hidden form fields in the templates
  • The value comes from translations['printText'] which is properly initialized
  • Language configuration is handled via base64 encoded JSON with fallback to default text
  • Default German language handling is implemented with proper fallback
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for translation files and printText key usage
echo "Searching for translation files..."
fd -e yml -e yaml . | while read -r file; do
  echo "=== $file ==="
  # Look for printText related translations
  grep -A 2 "printText:" "$file" || true
done

# Search for other usages of printText in the codebase
echo -e "\nSearching for printText usage in PHP files..."
rg "printText" -t php

echo -e "\nSearching for printText usage in Twig templates..."
rg "printText" -t twig

Length of output: 9823


Script:

#!/bin/bash
# Search for language configuration and defaultPrintText settings
echo "Searching for language configuration files..."
fd -e php -e json -e yaml -e yml . | xargs rg -l "defaultPrintText|languageConfig" || true

echo -e "\nSearching for specific language configuration implementation..."
rg -A 5 "defaultPrintText" || true

echo -e "\nChecking Index.php implementation..."
cat zmsticketprinter/src/Zmsticketprinter/Index.php || true

Length of output: 6373

Comment on lines 8 to 10
{% if printText %}
. {{ printText }}
{% endif %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Add HTML escaping for printText to prevent XSS

The printText value is rendered directly in the template without escaping, which could lead to XSS vulnerabilities if the content contains malicious HTML/JavaScript.

Apply this change:

-			. {{ printText }}
+			. {{ printText|escape }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{% if printText %}
. {{ printText }}
{% endif %}
{% if printText %}
. {{ printText|escape }}
{% endif %}

@@ -32,6 +32,7 @@ public function readResponse(
$validator = $request->getAttribute('validator');
$scopeId = $validator->getParameter('scopeId')->isNumber()->getValue();
$requestId = $validator->getParameter('requestId')->isNumber()->getValue();
$printText = $validator->getParameter('printText')->isString()->getValue();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add length validation for printText parameter

While type validation is implemented, there's no maximum length restriction on the printText parameter. This could potentially lead to very large strings being processed and displayed.

Consider adding length validation:

-        $printText = $validator->getParameter('printText')->isString()->getValue();
+        $printText = $validator->getParameter('printText')->isString()->matchLength(1, 255)->getValue();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$printText = $validator->getParameter('printText')->isString()->getValue();
$printText = $validator->getParameter('printText')->isString()->matchLength(1, 255)->getValue();

Comment on lines +67 to +69
if (empty($currentLang) || $currentLang === 'de') {
$translations['printText'] = $languageConfig['defaultPrintText'] ?? '';
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Simplify language condition and validate config structure

The current implementation could be improved in two ways:

  1. The language condition could be simplified
  2. The languageConfig structure should be validated

Consider this approach:

+        if (!isset($languageConfig['defaultPrintText'])) {
+            throw new \InvalidArgumentException('Missing defaultPrintText in language config');
+        }
+
-        if (empty($currentLang) || $currentLang === 'de') {
-            $translations['printText'] = $languageConfig['defaultPrintText'] ?? '';
-        }
+        $translations['printText'] = ($currentLang === 'de' || empty($currentLang))
+            ? $languageConfig['defaultPrintText']
+            : '';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (empty($currentLang) || $currentLang === 'de') {
$translations['printText'] = $languageConfig['defaultPrintText'] ?? '';
}
if (!isset($languageConfig['defaultPrintText'])) {
throw new \InvalidArgumentException('Missing defaultPrintText in language config');
}
$translations['printText'] = ($currentLang === 'de' || empty($currentLang))
? $languageConfig['defaultPrintText']
: '';

@@ -14,6 +14,7 @@
{{ hiddenfield({ "name": "scopeId", "value": ticketprinter.buttons|first.scope.id }) }}
{{ hiddenfield({ "name": "clusterId", "value": ticketprinter.buttons|first.cluster.id }) }}
{{ hiddenfield({ "name": "requestId", "value": button.requestId }) }}
{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add null check and ensure XSS prevention

While adding the printText hidden field aligns with the PR objective, consider these security and robustness improvements:

  1. Add a null check for the translations array
  2. Ensure proper escaping of the translation value
-{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
+{{ hiddenfield({ "name": "printText", "value": translations['printText']|default('')|escape }) }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
{{ hiddenfield({ "name": "printText", "value": translations['printText']|default('')|escape }) }}

@@ -69,6 +71,7 @@
{{ hiddenfield({ "name": "scopeId", "value": button.scope.id }) }}
{{ hiddenfield({ "name": "clusterId", "value": button.cluster.id }) }}
{{ hiddenfield({ "name": "requestId", "value": button.requestId }) }}
{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Maintain consistent implementation with other blocks

Apply the same null check and escaping improvements as suggested for the other blocks.

-{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
+{{ hiddenfield({ "name": "printText", "value": translations['printText']|default('')|escape }) }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
{{ hiddenfield({ "name": "printText", "value": translations['printText']|default('')|escape }) }}

@@ -43,6 +44,7 @@
{{ hiddenfield({ "name": "scopeId", "value": button.scope.id }) }}
{{ hiddenfield({ "name": "clusterId", "value": button.cluster.id }) }}
{{ hiddenfield({ "name": "requestId", "value": button.requestId }) }}
{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Maintain consistent implementation with button_single

Apply the same null check and escaping improvements as suggested for the button_single block.

-{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
+{{ hiddenfield({ "name": "printText", "value": translations['printText']|default('')|escape }) }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{ hiddenfield({ "name": "printText", "value": translations['printText'] }) }}
{{ hiddenfield({ "name": "printText", "value": translations['printText']|default('')|escape }) }}

@manjencic manjencic merged commit aee4ae8 into next Dec 19, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants